EventManager.prototype.registerListener=function (listener){
	if (this.listeners.hasValue(listener)){
		return;
	}
	this.listeners.push(listener);
}


EventManager.prototype.unregisterListener=function (listener) {
	this.listeners.removeAll(listener);
}


EventManager.prototype.fireEvent=function (eventName, params) {
	var handlerName="on"+eventName;
	for (var i=0; i<this.listeners.length; i++){
		if (handlerName in this.listeners[i]){
			this.listeners[i][handlerName](params);
		}
	}
}

EventManager.prototype.hookupManager=function (element, nativeEvent, customEvent){
	if (!customEvent){
		customEvent=nativeEvent;
	}
	
	EventManager.hookupHandler(element, nativeEvent, EventManager.createHandler(this, "fireEvent", customEvent));
}

EventManager.createHandler=function (listener, functionName, params){
	var func=new Function("arguments.callee.target."+functionName+"(arguments.callee.params);");
	func.target=listener;
	func.params=params;
	return func;
}

EventManager.hookupHandler=function (element, eventName, handler) {
	if (element.attachEvent){	
		element.attachEvent("on"+eventName, handler);
	}
	if (element.addEventListener) {
		element.addEventListener(eventName, handler, true);
	}

}

function EventManager(){
	this.listeners=new Array();
	
	Framework.instance.registerFinalizer(this);	
}

EventManager.prototype.finalize = function () {
    this.listeners.removeAll();
}


